home *** CD-ROM | disk | FTP | other *** search
Wrap
<?php /* +-------------------------------------------------------------------------- | IBFORUMS v1 | ======================================== | by Matthew Mecham and David Baxter | (c) 2001,2002 IBForums | http://www.ibforums.com | ======================================== | Web: http://www.ibforums.com | Email: phpboards@ibforums.com | Licence Info: phpib-licence@ibforums.com +--------------------------------------------------------------------------- | | > Forum topic index module | > Module written by Matt Mecham | > Date started: 14th February 2002 | | > Module Version Number: 1.0.0 +-------------------------------------------------------------------------- */ $idx = new Forums; class Forums { var $output = ""; var $base_url = ""; var $html = ""; var $moderator = array(); var $forum = array(); var $show_dots = ""; var $nav_extra = ""; var $read_array = array(); //+---------------------------------------------------------------- // // Our constructor, load words, load skin, get DB forum/cat data // //+---------------------------------------------------------------- function Forums() { global $ibforums, $DB, $std, $print, $skin_universal; require "./Skin/".$ibforums->skin_id."/skin_forum.php"; $ibforums->input['f'] = intval($ibforums->input['f']); $ibforums->lang = $std->load_words($ibforums->lang, 'lang_forum', $ibforums->lang_id); $this->html = new skin_forum(); // Get the forum info based on the forum ID, and get the category name, ID, etc. $DB->query("SELECT f.*, c.id as cat_id, c.name as cat_name from ibf_forums f, ibf_categories c WHERE f.id=".$ibforums->input['f']." and c.id=f.category"); $this->forum = $DB->fetch_row(); //---------------------------------------- // Error out if we can not find the forum //---------------------------------------- if (!$this->forum['id']) { $std->Error( array( LEVEL => 1, MSG => 'missing_files') ); } //---------------------------------------- // If this is a sub forum, we need to get // the cat details, and parent details //---------------------------------------- if ($this->forum['parent_id'] > 0) { $DB->query("SELECT f.id as forum_id, f.name as forum_name, c.id, c.name FROM ibf_forums f, ibf_categories c WHERE f.id='".$this->forum['parent_id']."' AND c.id=f.category"); $row = $DB->fetch_row(); $this->forum['cat_id'] = $row['id']; $this->forum['cat_name'] = $row['name']; $this->nav_extra = "<a href='".$ibforums->base_url."&act=SF&f={$row['forum_id']}'>{$row['forum_name']}</a>"; } //---------------------------------------- // // If this is a sub forum, bounce back. // //---------------------------------------- if ($this->forum['subwrap'] == 1) { $std->boink_it($ibforums->base_url."&sub=1&f=".$this->forum['id']); exit(); } //-------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- $this->base_url = "{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}?s={$ibforums->session_id}"; $this->forum['FORUM_JUMP'] = $std->build_forum_jump(); $this->forum['FORUM_JUMP'] = preg_replace( "!#Forum Jump#!", $ibforums->lang['forum_jump'], $this->forum['FORUM_JUMP']); // Are we viewing the forum, or viewing the forum rules? if ($ibforums->input['act'] == 'SR') { $this->show_rules(); } else { $this->show_forum(); } } //+---------------------------------------------------------------- // // Show the forum rules on a seperate page // //+---------------------------------------------------------------- function show_rules() { global $DB, $ibforums, $std, $print; //+-------------------------------------------- // Do we have permission to view these rules? //+-------------------------------------------- $bad_entry = $this->check_access(); if ($bad_entry == 1) { $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_view_topic') ); } //+-------------------------------------------- // Get the rules from the DB //+-------------------------------------------- $DB->query("SELECT * FROM ibf_rules WHERE fid='".$ibforums->input['f']."'"); if ( $rules = $DB->fetch_row() ) { $rules['title'] = stripslashes($rules['title']); $rules['body'] = stripslashes($rules['body']); $this->output .= $this->html->show_rules($rules); $print->add_output("$this->output"); $print->do_output( array( 'TITLE' => "IBForums -> ".$this->forum['name'], 'JS' => 0, 'NAV' => array( "<a href='".$this->base_url."&act=SC&c={$this->forum['cat_id']}'>{$this->forum['cat_name']}</a>", ), ) ); } else { $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_view_topic') ); } } //+---------------------------------------------------------------- // // Forum view check for authentication // //+---------------------------------------------------------------- function show_forum() { global $ibforums; // are we checking for user authentication via the log in form // for a private forum w/password protection? $ibforums->input['L'] == 1 ? $this->authenticate_user() : $this->render_forum(); } //+---------------------------------------------------------------- // // Authenicate the log in for a password protected forum // //+---------------------------------------------------------------- function authenticate_user() { global $std, $ibforums, $print; if ($ibforums->input['f_password'] == "") { $std->Error( array( 'LEVEL' => 1, 'MSG' => 'pass_blank' ) ); } if ($ibforums->input['f_password'] != $this->forum['password']) { $std->Error( array( 'LEVEL' => 1, 'MSG' => 'wrong_pass' ) ); } $std->my_setcookie( "iBForum".$this->forum['id'], $ibforums->input['f_password'] ); $print->redirect_screen( $ibforums->lang['logged_in'] , "act=SF&f=".$this->forum['id'] ); } //+---------------------------------------------------------------------------------- function check_access() { global $ibforums, $HTTP_COOKIE_VARS; $return = 1; if ($this->forum['read_perms'] == '*') { $return = 0; } else if (preg_match( "/(^|,)".$ibforums->member['mgroup']."(,|$)/", $this->forum['read_perms'] ) ) { $return = 0; } if ($this->forum['password']) { if ($HTTP_COOKIE_VARS[ $ibforums->vars['cookie_id'].'iBForum'.$this->forum['id'] ] == $this->forum['password']) { $return = 0; } else { $this->forum_login(); } } return $return; } //+---------------------------------------------------------------------------------- function forum_login() { global $ibforums, $std, $DB, $HTTP_COOKIE_VARS, $print; if (empty($ibforums->member['id'])) { $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_guests' ) ); } $this->output = $this->html->Forum_log_in( $this->forum['id'] ); $print->add_output("$this->output"); $print->do_output( array( 'TITLE' => $ibforums->vars['board_name']." -> ".$this->forum['name'], 'JS' => 0, 'NAV' => array( "<a href='".$this->base_url."&act=SC&c={$this->forum['cat_id']}'>{$this->forum['cat_name']}</a>", "<a href='".$this->base_url."&act=SF&f={$this->forum['id']}'>{$this->forum['name']}</a>", ), ) ); } //+---------------------------------------------------------------- // // Main render forum engine // //+---------------------------------------------------------------- function render_forum() { global $ibforums, $DB, $std, $print, $HTTP_COOKIE_VARS; $bad_entry = $this->check_access(); if ($bad_entry == 1) { $std->Error( array( LEVEL => 1, MSG => 'no_permission') ); } if ( $read = $std->my_getcookie('topicsread') ) { $this->read_array = unserialize(stripslashes($read)); } if ( $forum = $std->my_getcookie('fread_'.$ibforums->input['f']) ) { $ibforums->input['last_visit'] = $forum > $ibforums->input['last_visit'] ? $forum : $ibforums->input['last_visit']; } $prune_value = $std->select_var( array( 1 => $ibforums->input['prune_day'], 2 => $this->forum['prune'] , 3 => '100' ) ); $sort_key = $std->select_var( array( 1 => $ibforums->input['sort_key'], 2 => $this->forum['sort_key'] , 3 => 'last_post' ) ); $sort_by = $std->select_var( array( 1 => $ibforums->input['sort_by'], 2 => $this->forum['sort_order'] , 3 => 'Z-A' ) ); $First = $std->select_var( array( 1 => $ibforums->input['st'], 2 => 0 ) ); // Figure out sort order, day cut off, etc $Prune = $prune_value != 100 ? (time() - ($prune_value * 60 * 60 * 24)) : 0; $sort_keys = array( 'last_post' => 'sort_by_date', 'title' => 'sort_by_topic', 'starter_name' => 'sort_by_poster', 'posts' => 'sort_by_replies', 'views' => 'sort_by_views', 'start_date' => 'sort_by_start', 'last_poster_name' => 'sort_by_last_poster', ); $prune_by_day = array( '1' => 'show_today', '5' => 'show_5_days', '7' => 'show_7_days', '10' => 'show_10_days', '15' => 'show_15_days', '20' => 'show_20_days', '25' => 'show_25_days', '30' => 'show_30_days', '60' => 'show_60_days', '90' => 'show_90_days', '100' => 'show_all', ); $sort_by_keys = array( 'Z-A' => 'descending_order', 'A-Z' => 'ascending_order', ); //+---------------------------------------------------------------- // check for any form funny business by wanna-be hackers //+---------------------------------------------------------------- if ( (!isset($sort_keys[$sort_key])) and (!isset($prune_by_day[$prune_value])) and (!isset($sort_by_keys[$sort_by])) ) { $std->Error( array( LEVEL=> 5, MSG =>'incorrect_use') ); } $r_sort_by = $sort_by == 'A-Z' ? 'ASC' : 'DESC'; //+---------------------------------------------------------------- // Query the database to see how many topics there are in the forum //+---------------------------------------------------------------- $DB->query("SELECT COUNT(tid) as max FROM ibf_topics WHERE forum_id='".$this->forum['id']."' and approved='1' and (last_post > $Prune or pinned=1)"); $total_possible = $DB->fetch_row(); //+---------------------------------------------------------------- // Generate the forum page span links //+---------------------------------------------------------------- $this->forum['SHOW_PAGES'] = $std->build_pagelinks( array( TOTAL_POSS => $total_possible[max], PER_PAGE => $ibforums->vars['display_max_topics'], CUR_ST_VAL => $ibforums->input['st'], L_SINGLE => $ibforums->lang['single_page_forum'], L_MULTI => $ibforums->lang['multi_page_forum'], BASE_URL => $this->base_url."&act=SF&f=".$this->forum['id']."&prune_day=$prune_value&sort_by=$sort_by&sort_order=$sort_order", ) ); //+---------------------------------------------------------------- // Do we have any rules to show? //+---------------------------------------------------------------- if ($this->forum['show_rules']) { $DB->query("SELECT * from ibf_rules WHERE fid='".$this->forum['id']."'"); if ( $rules = $DB->fetch_row() ) { $rules['title'] = stripslashes($rules['title']); $rules['body'] = stripslashes($rules['body']); $this->output .= $rules['show_all'] ? $this->html->show_rules_full($rules) : $this->html->show_rules_link($rules); } } //+---------------------------------------------------------------- // Generate the poll button //+---------------------------------------------------------------- $this->forum['POLL_BUTTON'] = $this->forum['allow_poll'] ? "<a href='".$this->base_url."&act=Post&CODE=10&f=".$this->forum['id']."'>{$ibforums->skin['A_POLL']}</a>" : ''; //+---------------------------------------------------------------- // Start printing the page //+---------------------------------------------------------------- $this->output .= $this->html->PageTop($this->forum); //+---------------------------------------------------------------- // Do we have any topics to show? //+---------------------------------------------------------------- if ($total_possible['max'] < 1) { $this->output .= $this->html->show_no_matches(); } $total_topics_printed = 0; if ( ($ibforums->vars['show_user_posted'] == 1) and ($ibforums->member['id']) ) { $query = "SELECT DISTINCT ibf_posts.author_id, ibf_topics.* from ibf_topics LEFT JOIN ibf_posts ON (ibf_topics.tid = ibf_posts.topic_id AND ibf_posts.author_id = '".$ibforums->member['id']."') WHERE ibf_topics.forum_id='".$this->forum['id']."' and (ibf_topics.last_post > '$Prune' OR ibf_topics.pinned='1') and ibf_topics.approved='1'"; } else { $query = "SELECT * from ibf_topics WHERE forum_id='".$this->forum['id']."' and approved='1' and (last_post > '$Prune' OR pinned='1')"; } //+---------------------------------------------------------------- // Do we have permission to view other posters topics? //+---------------------------------------------------------------- if (!$ibforums->member['g_other_topics']) { $query .= " and starter_id='".$ibforums->member['id']."'"; } //+---------------------------------------------------------------- // Finish off the query //+---------------------------------------------------------------- $First = $First ? $First : 0; $query .= " ORDER BY pinned DESC, $sort_key $r_sort_by LIMIT $First,".$ibforums->vars['display_max_topics']; $DB->query($query); //+---------------------------------------------------------------- // Grab the rest of the topics and print them //+---------------------------------------------------------------- while ( $topic = $DB->fetch_row() ) { $this->output .= $this->render_entry( $topic ); $total_topics_printed++; } //+---------------------------------------------------------------- // Finish off the rest of the page //+---------------------------------------------------------------- $ibforums->lang['showing_text'] = preg_replace( "/<#MATCHED_TOPICS#>/", $total_topics_printed , $ibforums->lang['showing_text'] ); $ibforums->lang['showing_text'] = preg_replace( "/<#TOTAL_TOPICS#>/" , $total_possible['max'] , $ibforums->lang['showing_text'] ); $sort_key_html = "<select name='sort_key' class='forminput'>\n"; $prune_day_html = "<select name='prune_day' class='forminput'>\n"; $sort_by_html = "<select name='sort_by' class='forminput'>\n"; foreach ($sort_by_keys as $k => $v) { $sort_by_html .= $k == $sort_by ? "<option value='$k' selected>" . $ibforums->lang[ $sort_by_keys[ $k ] ] . "\n" : "<option value='$k'>" . $ibforums->lang[ $sort_by_keys[ $k ] ] . "\n"; } foreach ($sort_keys as $k => $v) { $sort_key_html .= $k == $sort_key ? "<option value='$k' selected>" . $ibforums->lang[ $sort_keys[ $k ] ] . "\n" : "<option value='$k'>" . $ibforums->lang[ $sort_keys[ $k ] ] . "\n"; } foreach ($prune_by_day as $k => $v) { $prune_day_html .= $k == $prune_value ? "<option value='$k' selected>" . $ibforums->lang[ $prune_by_day[ $k ] ] . "\n" : "<option value='$k'>" . $ibforums->lang[ $prune_by_day[ $k ] ] . "\n"; } $ibforums->lang['sort_text'] = preg_replace( "!<#SORT_KEY_HTML#>!", "$sort_key_html</select>" , $ibforums->lang['sort_text'] ); $ibforums->lang['sort_text'] = preg_replace( "!<#ORDER_HTML#>!" , "$sort_by_html</select>" , $ibforums->lang['sort_text'] ); $ibforums->lang['sort_text'] = preg_replace( "!<#PRUNE_HTML#>!" , "$prune_day_html</select>" , $ibforums->lang['sort_text'] ); $this->output .= $this->html->TableEnd($this->forum); //+---------------------------------------------------------------- // Are we a moderator? //+---------------------------------------------------------------- if ( ($ibforums->member['id']) and ($ibforums->member['g_is_supmod'] != 1) ) { $DB->query("SELECT mid FROM ibf_moderators WHERE forum_id='".$this->forum['id']."' and member_id='".$ibforums->member['id']."'"); $this->moderator = $DB->fetch_row(); } //+---------------------------------------------------------------- // Do we have to print the moderators CP link? //+---------------------------------------------------------------- if ($ibforums->member['g_is_supmod'] or $this->moderator['mid']) { $this->output .= $this->html->Mod_Panel( $this->forum['id'] ); } //+---------------------------------------------------------------- // Print it //+---------------------------------------------------------------- $print->add_output("$this->output"); $print->do_output( array( 'TITLE' => $ibforums->vars['board_name']." -> ".$this->forum['name'], 'JS' => 0, 'NAV' => array( "<a href='".$this->base_url."&act=SC&c={$this->forum['cat_id']}'>{$this->forum['cat_name']}</a>", $this->nav_extra, "<a href='".$this->base_url."&act=SF&f={$this->forum['id']}'>{$this->forum['name']}</a>", ), ) ); } //+---------------------------------------------------------------- // // Crunches the data into pwetty html // //+---------------------------------------------------------------- function render_entry($topic) { global $DB, $std, $ibforums; $topic['last_text'] = $ibforums->lang['last_post_by']; $topic['last_poster'] = ($topic['last_poster_id'] != 0) ? "<b><a href='{$this->base_url}&act=Profile&CODE=03&MID={$topic['last_poster_id']}'>{$topic['last_poster_name']}</a></b>" : "-".$topic['last_poster_name']."-"; $topic['starter'] = ($topic['starter_id'] != 0) ? "<a href='{$this->base_url}&act=Profile&CODE=03&MID={$topic['starter_id']}'>{$topic['starter_name']}</a>" : "-".$topic['starter_name']."-"; if ($topic['poll_state']) { $topic['prefix'] = $ibforums->vars['pre_polls'].' '; } if ( ($ibforums->member['id']) and ($topic['author_id']) ) { $show_dots = 1; } $topic['folder_img'] = $std->folder_icon($topic, $show_dots, $this->read_array[$topic['tid']]); $topic['topic_icon'] = $topic['icon_id'] ? '<img src="'.$ibforums->vars['img_url'] . '/icon' . $topic['icon_id'] . '.gif" border="0" alt="">' : ' '; $topic['start_date'] = $std->get_date( $topic['start_date'], 'LONG' ); $pages = 1; if ($topic['posts']) { if ( (($topic['posts'] + 1) % $ibforums->vars['display_max_posts']) == 0 ) { $pages = ($topic['posts'] + 1) / $ibforums->vars['display_max_posts']; } else { $number = ( ($topic['posts'] + 1) / $ibforums->vars['display_max_posts'] ); $pages = ceil( $number); } } if ($pages > 1) { $topic['PAGES'] = "<span id='small'>({$ibforums->lang['topic_sp_pages']} "; for ($i = 0 ; $i < $pages ; ++$i ) { $real_no = $i * $ibforums->vars['display_max_posts']; $page_no = $i + 1; if ($page_no == 4) { $topic['PAGES'] .= "<a href='{$this->base_url}&act=ST&f={$this->forum['id']}&t={$topic['tid']}&st=" . ($pages - 1) * $ibforums->vars['display_max_posts'] . "'>...$pages </a>"; break; } else { $topic['PAGES'] .= "<a href='{$this->base_url}&act=ST&f={$this->forum['id']}&t={$topic['tid']}&st=$real_no'>$page_no </a>"; } } $topic['PAGES'] .= ")</span>"; } if ($topic['posts'] < 0) $topic['posts'] = 0; $last_time = $this->read_array[ $topic['tid'] ] > $ibforums->input['last_visit'] ? $this->read_array[ $topic['tid'] ] : $ibforums->input['last_visit']; if ($last_time && ($topic['last_post'] > $last_time)) { $topic['go_last_page'] = "<a href='{$this->base_url}&act=ST&f={$this->forum['id']}&t={$topic['tid']}&view=getlastpost'>" . $ibforums->skin['GO_LAST_ON'] . "</a>"; $topic['go_new_post'] = "<a href='{$this->base_url}&act=ST&f={$this->forum['id']}&t={$topic['tid']}&view=getnewpost'>" . $ibforums->skin['NEW_POST'] . "</a>"; } else { $topic['go_last_page'] = "<a href='{$this->base_url}&act=ST&f={$this->forum['id']}&t={$topic['tid']}&view=getlastpost'>" . $ibforums->skin['GO_LAST_OFF'] . "</a>"; $topic['go_new_post'] = ""; } $topic['last_post'] = $std->get_date( $topic['last_post'], 'SHORT' ); //+---------------------------------------------------------------- if ($topic['state'] == 'link') { $t_array = explode("&", $topic['moved_to']); $topic['tid'] = $t_array[0]; $topic['forum_id'] = $t_array[1]; $topic['title'] = $topic['title']; $topic['views'] = '--'; $topic['posts'] = '--'; $topic['prefix'] = $ibforums->vars['pre_moved']." "; $topic['go_new_post'] = ""; } if ($topic['pinned'] == 1) { $topic['prefix'] = $ibforums->vars['pre_pinned']; $topic['topic_icon'] = $ibforums->skin['B_PIN']; } return $this->html->RenderRow( $topic ); } //+---------------------------------------------------------------- // // Returns the last action date // //+---------------------------------------------------------------- function get_last_date($topic) { global $ibforums, $std; return $std->get_date( $topic['last_post'], 'SHORT' ); } } ?>